package com.ruoyi.system.callback;

import cn.hutool.core.util.HexUtil;
import com.ruoyi.generator.annocation.MqttCallbackKey;
import com.ruoyi.generator.callback.MqttCallbackObserver;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.stereotype.Component;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

@Component
@MqttCallbackKey("11111")
@Slf4j
public class LogMqttCallBack extends MqttCallbackObserver {
    @Override
    public void connectComplete(boolean reconnect, String serverURI) {
        log.info("connectComplete , {}",serverURI);

    }

    @Override
    public void connectionLost(Throwable cause) {
        cause.printStackTrace();
    }

    @Override
    public void messageArrived(String topic, MqttMessage message) throws Exception {
        log.info("messageArrived , {} {} ",topic, HexUtil.format(new String(HexUtil.encodeHex(message.getPayload()))));
    }

    @Override
    public void deliveryComplete(IMqttDeliveryToken token) {
        log.info("deliveryComplete , {} ",token);
    }
}
